cmake_minimum_required(VERSION 3.5.2)
project(DNNLibrary)

option(DNN_BUILD_BIN "Build binaries" ON)
option(DNN_BUILD_JNI "Build Java Wrapper" OFF)
option(DNN_READ_ONNX "Read ONNX model directly instead of converting to .daq" OFF)
option(DNN_SYSTEM_PROTOBUF "Use system protobuf when building onnx2daq" OFF)
option(DNN_BUILD_PYTHON "Build Python wrapper for onnx2daq" ON)
option(DNN_USE_MSVC_STATIC_RUNTIME "Link onnx2daq to msvc static runtime" ON)
option(DNN_CMAKE_INSTALL "Export targets in cmake (disable it for ONNXRuntime)" ON)

include(cmake/system.cmake)
include(cmake/common.cmake)

include(cmake/utils.cmake)
dnn_add_msvc_runtime_flag()

include(cmake/glog.cmake)
configure_glog()

include(cmake/flatbuffers.cmake)
configure_flatbuffers()

if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
    set (CMAKE_CXX_STANDARD 17)

    add_compile_options(-Os)
    if (${DNN_READ_ONNX})
        include(cmake/onnx.cmake)
        configure_onnx()
        set(ONNX2DAQ_ONLY_LIB ON)
        add_subdirectory(tools)
    else()
        add_compile_options(-fno-rtti)
    endif()
    add_subdirectory(dnnlibrary)
    add_subdirectory(binaries)
else()
    set (CMAKE_CXX_STANDARD 11)
    if (MSVC)
        set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1)
    endif()
    if (${DNN_BUILD_PYTHON})
        set(CMAKE_POSITION_INDEPENDENT_CODE ON)
        add_subdirectory(third_party/pybind11)
    endif()

    if (${DNN_SYSTEM_PROTOBUF})
        find_package(Protobuf)
    endif()
    if (NOT Protobuf_FOUND)
        set(DNN_SYSTEM_PROTOBUF OFF CACHE BOOL "Use system protobuf when building onnx2daq" FORCE)
    endif()

    include(cmake/onnx.cmake)
    configure_onnx()
    add_subdirectory(tools)
endif()
